package org.csu.jpetstore.bo;

import lombok.Data;
import org.csu.jpetstore.entity.Inventory;
import org.csu.jpetstore.entity.Item;

import java.math.BigDecimal;

/**
 * @author huangzhangyan
 */
@Data
public class ItemBO {

    //category表中
    private String categoryId;

    // Item 表中
    private String itemId;
    private String productId;
    private BigDecimal listPrice;
    private BigDecimal unitCost;
    private Integer supplierId;
    private String attribute;
    private String status;
    private String image;

    // inventory 表中
    private Integer quantity;

    private ItemBO(String categoryId, Item itemEntity, Inventory inventory) {
        this.categoryId = categoryId;
        this.itemId = itemEntity.getItemId();
        this.productId = itemEntity.getProductId();
        this.listPrice = itemEntity.getListPrice();
        this.unitCost = itemEntity.getUnitCost();
        this.supplierId = itemEntity.getSupplierId();
        this.attribute = itemEntity.getAttribute();
        this.status = itemEntity.getStatus();
        this.quantity = inventory.getQuantity();
        this.image = itemEntity.getImage();
    }

    public static ItemBO toItemBO(String categoryId, Item itemEntity, Inventory inventory) {
        if (itemEntity == null || inventory == null)
            return null;
        return new ItemBO(categoryId, itemEntity, inventory);
    }
}
